package com.bw.repair.vm

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.common.vm.BaseViewModel
import com.bw.repair.entity.AddRepairEntity
import com.bw.repair.entity.RepairEntityItem
import com.bw.repair.model.RepairRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
@HiltViewModel
class RepairViewModel @Inject constructor(private val repo:RepairRepository):BaseViewModel() {
    val mRepairSuccess = MutableLiveData<List<RepairEntityItem>>()
    fun getRepairData(){
        viewModelScope.launch(mDispatcher) {
            val res = repo.loadRepairData()
            if (res.code == 200){
                mRepairSuccess.postValue(res.data)
            }else{
                mError.postValue("请求失败${res.message}")
            }
        }
    }

    //添加维修工单
    val mAddRepairSuccess = MutableLiveData<AddRepairEntity>()

    fun getAddRepairData(addRepairEntity: AddRepairEntity){
        viewModelScope.launch(mDispatcher) {
            val res = repo.loadAddRepairData(addRepairEntity)
            if (res.code ==200){
                mAddRepairSuccess.postValue(res.data)
            }else{
                mError.postValue("请求失败${res.message}")
            }
        }
    }
}